import requests, queue, re, json, random, threading


def parse_(url):
    r = requests.get(url)
    print(type(r.text))
    img_urls = re.findall('"rs16":"(.*?)"', r.text)
    print(img_urls)
    return img_urls

def download_img(url):
    r = requests.get(url)
    with open('/home/python/Desktop/斗鱼img/' + url[:5], 'wb') as f:
        f.write(r.content)


def run(url):
    l = []
    for i in parse_(url):
        q.put(i)
    for i in range(10):
        t = threading.Thread(target=download_img, args=(q.get()))
        t.start()
        l.append(t)
    for t in l:
        t.join()


if __name__ == '__main__':
    q = queue.Queue()
    url = 'https://www.douyu.com/gapi/rknc/directory/yzRec/1'
    run(url)
